
<?php 
	$card = $this->card;
	if($card->total <= 0){
		//if($this->message!=''){
			echo $this->partial('partial/message.phtml','default',array(
					'message'=>'Chưa có sản phẩm trong giỏ hàng',
					'status'=>'error'
			));
		//}
	}else{
?>

<form action="<?php echo $this->baseUrl('/default/order/update/lang/'.LANG)?>" method="post" id="frm-card">
			<table class='table'>
				<thead>
					<tr>
						<th>Xóa</th>
						<th>Tên sản phẩm</th>
						<th>Số lượng ( VND )</th>
						<th>Đơn giá ( VND )</th>
						<th>Thành tiền ( VND )</th>
					</tr>
				</thead>
				<tbody>
				<?php 
					
					
					
					//lấy danh sách sản phẩm
					$products = $card->items;
					
					//tổng tiền
					$total=0;
					
					//product model
					$pMD = new Application_Model_DbTable_Product();
					$intCount = 0;
					foreach($products as $k =>$v)
					{
						$intCount ++;
						$product = $pMD->fetchRow($pMD->select()->where('product_id = ?',$k));
						$sum = $product['product_price'] * $v;
						$total +=$sum;
						
				?>
				<tr class='card-item'>
					<td>
						<a href="<?php echo $this->baseUrl('/default/order/delete/id/'.$k.'/lang/'.LANG)?>" title="xóa"
						class="card-delete" >
						<span>&nbsp;xóa</span></a>
					</td>
					<td><a href="<?php echo $this->baseUrl('/'.LANG.'/san-pham/chi-tiet/'.$product['product_id'].'-'.$product['product_alias'].'.html')?>"><?php echo $product['product_name']?></a></td>
					<td class="text-center">
						<input type="text" value="<?php echo $v?>" name="qty<?php echo $intCount;?>" class="quantity" />
					</td>
					<td><?php echo number_format($product['product_price'])?> </td>
					<td><?php echo number_format($sum)?> </td>
				</tr>
				<?php }?>
				<tr>
					<td colspan="5" id="total-price">Tổng giá đơn hàng: <span><?php echo number_format($total)?></span> </td>
				</tr>
				</tbody>
			</table>
			
			<!--  các nút điều kiển -->
			<div class="card-controller">
				<!--  mua tiep-->
				<a href="<?php echo $this->baseUrl('/'.LANG.'/')?>"><?php echo $this->translate('Mua tiếp')?></a> 
				
				<a href="<?php echo $this->baseUrl('/'.LANG.'/gio-hang/huy.html')?>"><?php echo $this->translate('Hủy')?></a>
				<a href="#" id="submit-frm-card"><?php echo $this->translate('Cập nhật')?></a> 
				<a href="<?php echo $this->baseUrl('/'.LANG.'/gio-hang/dat-hang.html')?>"><?php echo $this->translate('Đặt hàng')?></a>
			</div>			
			<!-- End card-controller -->
		</form>
<?php }?>
		<script>
			$(document).ready(function(){

				$(".quantity").blur(function(){
					var _this = $(this);
					var val=$(this).val();
					var name=$(this).attr("name");
					var isnum = /^\d+$/.test(val);
					if(isnum==false){
						alert("chỉ được nhập số");				
						document.getElementsByName(name)[0].value = _this.attr("value");

					}
				});
				$("#submit-frm-card").click(function(){
					$("#frm-card").submit();
					return false;
				});
				//xóa sản phẩm trong giỏ hàng
				$(".card-delete").click(function(){
					var _this = $(this);
					var link = $(this).attr('href');
					$.ajax({
						type:"get",
						url: link,
						success:function(rdata){
							$("#card-count-item").html(rdata)
							var link = "<?php echo $this->baseUrl('/default/order/temp/lang/'.LANG)?>";
							$.ajax({
								type:"get",
								url:link,
								success:function(data){
									$("#card-detail").html(data);
									$("#card-count-item").html()	
								}
							});
						}
					});
					return false;
				});
			});
		</script>